import java.awt.Font;
import java.awt.LayoutManager;
import java.awt.Rectangle;

import javax.swing.DefaultListModel;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextField;
/**
 * Display Reader Report
 *
 */
public class ReaderReportResultGui extends JPanel {

	private static final long serialVersionUID = 1L;
	private JLabel jltlTitle = null;
	private JLabel jltlUserName = null;
	private JTextField jtxtUserName = null;
	private JScrollPane jScrollPane = null;
	private JList jlstResult = null;
	public JButton jbtnBack = null;
	/**
	 * temporary String []
	 */
	String[] tmp; 
	/**
	 * Create and initializes  ReaderReportResultGui
	 */
	public ReaderReportResultGui() {
		
		super();
		initialize();
	}

	public ReaderReportResultGui(LayoutManager arg0) {
		super(arg0);
		// TODO Auto-generated constructor stub
		initialize();
	}

	public ReaderReportResultGui(boolean arg0) {
		super(arg0);
		// TODO Auto-generated constructor stub
		initialize();
	}

	public ReaderReportResultGui(LayoutManager arg0, boolean arg1) {
		super(arg0, arg1);
		// TODO Auto-generated constructor stub
		initialize();
	}

	/**
	 * initializes this
	 * 
	 * @return void
	 */
	private void initialize() {
		jltlUserName = new JLabel();
		jltlUserName.setBounds(new Rectangle(16, 58, 71, 18));
		jltlUserName.setText("UserName:");
		jltlTitle = new JLabel();
		jltlTitle.setBounds(new Rectangle(110, 15, 144, 25));
		jltlTitle.setFont(new Font("Dialog", Font.BOLD, 18));
		jltlTitle.setText("Reader Report");
		this.setSize(400, 300);
		this.setLayout(null);
		this.add(jltlTitle, null);
		this.add(jltlUserName, null);
		this.add(getJtxtUserName(), null);
		this.add(getJScrollPane(), null);
		this.add(getJbtnBack(), null);
	}

	/**
	 * initializes jtxtUserName	
	 * 	
	 * @return JTextField	
	 */
	private JTextField getJtxtUserName() {
		if (jtxtUserName == null) {
			jtxtUserName = new JTextField();
			jtxtUserName.setBounds(new Rectangle(107, 58, 110, 19));
		}
		return jtxtUserName;
	}

	/**
	 *initializes jScrollPane	
	 * 	
	 * @return JScrollPane	
	 */
	private JScrollPane getJScrollPane() {
		if (jScrollPane == null) {
			jScrollPane = new JScrollPane();
			jScrollPane.setBounds(new Rectangle(14, 92, 333, 152));
			jScrollPane.setViewportView(getJlstResult());
		}
		return jScrollPane;
	}

	/**
	 *initializes jlstResult	
	 * 	
	 * @return javax.JList.JList	
	 */
	private JList getJlstResult() {
		if (jlstResult == null) {
			jlstResult = new JList();
		}
		return jlstResult;
	}

	/**
	 * initializes jbtnBack	and set it to Go Back
	 * 	
	 * @return JButton	
	 */
	private JButton getJbtnBack() {
		if (jbtnBack == null) {
			jbtnBack = new JButton();
			jbtnBack.setBounds(new Rectangle(134, 257, 117, 25));
			jbtnBack.setText("Back");
			jbtnBack.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {
					Main.pdmc=new PersonalDataManagmentCONTROL();
					Main.pdmc.lsreachUserug(false);
					Main.log.frame.setSize(900, 450);
					Main.rrc.rrg.setVisible(false);
					
				}
			});
			
		}
		return jbtnBack;
	}
	/**
	 * set jtxtUserName to user and disable it.
	 * @param user text which will be in jtxtUserName
	 */
	public void setUserName(String user)
	{
		jtxtUserName.setText(user);
		jtxtUserName.setEnabled(false);
	}
	/**
	 * Set data in list jlstResult
	 * @param data Array of String to be put in jlstResult list
	 */
	public void setList(String[] data)
	{
		int i;
		DefaultListModel l=new DefaultListModel();
		for(i=0;i<data.length;i++)
		{
			tmp=data[i].split("\\*");
			String[] date=tmp[2].split("\\-");
			tmp[2]=date[2]+"-"+date[1]+"-"+date[0];
			
			l.addElement(tmp[0]+" - "+tmp[1]+" Date :" + tmp[2]);
			
		}
		jlstResult.setModel(l);
		updateUI();
	}
}
